package com.test.adapter;

import com.test.demo.R;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class ImageListItemAdapter extends BaseAdapter {

	private Context mContext = null;
	private Resources mResources = null;
	
	// 定义整型数组 即图片源
	private Integer[]   mImageIds   =
		{
			R.drawable.img1,
			R.drawable.img2,
			R.drawable.img3,
			R.drawable.img4,
			R.drawable.img5,
			R.drawable.img6,
			R.drawable.img7,
			R.drawable.img8,
			R.drawable.img9,
	    };

	public ImageListItemAdapter(Context context){
		mContext   = context;	
		mResources = mContext.getResources();
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mImageIds.length;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View itemView;
		if (convertView == null)
		{
			LayoutInflater inflater = LayoutInflater.from(mContext);  
			itemView = inflater.inflate(R.layout.item_image_info, null); 

			//图像
			ImageView imageView = (ImageView)itemView.findViewById(R.id.item_image_imageView);
			if(imageView != null){
				imageView.setImageResource(mImageIds[position]);
			}
			
			//喜欢
			TextView likeText = (TextView)itemView.findViewById(R.id.item_image_like_textView);
			if(likeText != null){
				likeText.setText(mResources.getString(R.string.like) + "+1000");
			}
			
			//评论
			TextView commentText = (TextView)itemView.findViewById(R.id.item_image_comment_textView);
			if(commentText != null){
				commentText.setText(mResources.getString(R.string.comment) + "+50");
			}
			
			//分享
			TextView shareText = (TextView)itemView.findViewById(R.id.item_image_share_textView);
			if(shareText != null){
				shareText.setText(mResources.getString(R.string.share) + "+10");
			}
		}else{
			itemView = convertView;
		}
		
		return itemView;

	}

}
